# encoding:UTF-8

'''
创建简单的前向网络,神经网络为二层
'''
import tensorflow as tf

# 创建第一层权值
w1 = tf.Variable(tf.random_normal([2, 3], stddev=1, seed=1))
# 创建第二层权值
w2 = tf.Variable(tf.random_normal([3, 1], stddev=1, seed=1))

input = tf.constant([[0.7, 0.9]])

# 创建前向网络
a = tf.matmul(input, w1)
y = tf.matmul(a, w2)

# 创建session
with tf.Session(graph=tf.get_default_graph()) as sess:
    # sess.run(w1.initializer)
    # sess.run(w2.initializer)
    init_op = tf.global_variables_initializer()
    sess.run(init_op)
    print(sess.run(y))
    sess.close()

# 使用placeholder
x = tf.placeholder(tf.float32, shape=[3, 2], name='input')

a2 = tf.matmul(x, w1)
y2 = tf.matmul(a2, w2)

with tf.Session() as sess:
    init_op = tf.global_variables_initializer()
    sess.run(init_op)
    print(sess.run(y2, feed_dict={x: [[0.7, 0.9], [0.6, 0.8], [0.8, 0.9]]}))
    sess.close()
